package cm.tl.pms.util;


import lombok.extern.slf4j.Slf4j;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@Slf4j
public class DateUtil {
    static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    static SimpleDateFormat sdfTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    static SimpleDateFormat sdfT = new SimpleDateFormat("yyyyMMddHHmmss");
    static SimpleDateFormat sdfl = new SimpleDateFormat("yyyyMMddHHmmssSSS");
    static SimpleDateFormat sdfY = new SimpleDateFormat("yyyyMMdd");
    static SimpleDateFormat sdfD = new SimpleDateFormat("HHmmss");
    static SimpleDateFormat sdfChinese = new SimpleDateFormat("yyyy年MM月dd日");
    static SimpleDateFormat sdfS = new SimpleDateFormat("yyyy/MM/dd");
    static SimpleDateFormat sdfM = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS");


    public DateUtil() {
    }

    public static String format(Date date) {
        String str = null;
        if (date != null) {
            str = sdf.format(date);
        }

        return str;
    }

    public static Date parse(String str) {
        Date date = null;
        if (str != null) {
            try {
                date = sdf.parse(str);
            } catch (ParseException var3) {
                log.error(var3.getMessage());
            }
        }

        return date;
    }

    public static String formatTime(Date date) {
        String str = null;
        if (date != null) {
            str = sdfTime.format(date);
        }

        return str;
    }

    public static Date parseTime(String str) {
        Date date = null;
        if (str != null) {
            try {
                date = sdfTime.parse(str);
            } catch (ParseException var3) {
                log.error(var3.getMessage());
            }
        }

        return date;
    }

    public static String formatM(Date date) {
        String str = null;
        if (date != null) {
            str = sdfM.format(date);
        }

        return str;
    }

    public static Date parseM(String str) {
        Date date = null;
        if (str != null) {
            try {
                date = sdfM.parse(str);
            } catch (ParseException var3) {
                log.error(var3.getMessage());
            }
        }

        return date;
    }

    public static String formatT(Date date) {
        String str = null;
        if (date != null) {
            str = sdfT.format(date);
        }

        return str;
    }

    public static Date parseT(String str) {
        Date date = null;
        if (str != null) {
            try {
                date = sdfT.parse(str);
            } catch (ParseException var3) {
                log.error(var3.getMessage());
            }
        }

        return date;
    }

    public static String formatL(Date date) {
        String str = null;
        if (date != null) {
            str = sdfl.format(date);
        }

        return str;
    }

    public static Date parseL(String str) {
        Date date = null;
        if (str != null) {
            try {
                date = sdfl.parse(str);
            } catch (ParseException var3) {
                log.error(var3.getMessage());
            }
        }

        return date;
    }

    public static String formatChinese(Date date) {
        String str = null;
        if (date != null) {
            str = sdfChinese.format(date);
        }

        return str;
    }

    public static Date parseChinese(String str) {
        Date date = null;
        if (str != null) {
            try {
                date = sdfChinese.parse(str);
            } catch (ParseException var3) {
                log.error(var3.getMessage());
            }
        }

        return date;
    }

    public static String formatS(Date date) {
        String str = null;
        if (date != null) {
            str = sdfS.format(date);
        }

        return str;
    }

    public static Date parseS(String str) {
        Date date = null;
        if (str != null) {
            try {
                date = sdfS.parse(str);
            } catch (ParseException var3) {
                log.error(var3.getMessage());
            }
        }

        return date;
    }

    public static String formatY(Date date) {
        String str = null;
        if (date != null) {
            str = sdfY.format(date);
        }

        return str;
    }

    public static Date parseY(String str) {
        Date date = null;
        if (str != null) {
            try {
                date = sdfY.parse(str);
            } catch (ParseException var3) {
                log.error(var3.getMessage());
            }
        }

        return date;
    }

    public static void main(String[] args) {
        String time = formatL(new Date());
        System.out.println("====" + time);
    }

    public static String stamp2Date(String timeStamp) {
        return sdfl.format(new Date(Long.valueOf(timeStamp)));
    }

    public static String UTCtoLocal(String str) {
        String localTime = "";
        if (str != null) {
            try {
                str = str.replace("T", " ");
                str = str.replace("Z", "");
                Date date = sdfTime.parse(str);
                Long time = date.getTime() + 28800000L;
                localTime = sdfTime.format(new Date(time));
            } catch (Exception var4) {
                log.error(var4.getMessage());
            }
        }

        return localTime;
    }

    public static String LocaltoUTC(String str) {
        String utcTime = "";
        if (str != null) {
            try {
                Date date = sdfTime.parse(str);
                Long time = date.getTime() - 28800000L;
                utcTime = sdfTime.format(new Date(time));
            } catch (Exception var4) {
                log.error(var4.getMessage());
            }
        }

        return utcTime;
    }
}
